/**
 * 删除地址页面JS --> address.jsp
 * 
 * @author: 刘晓杰
 * @date: 2013-4-13
 */

var address = {
		init : function(){
			this.initElements();
		},
		
		initElements : function(){
			this.delAddressBtn = $('.delAddressBtn');
			this.initEvent();
		},
		
		initEvent : function(){
			this.delAddressBtn.click(this.deleteBtnAction());
		},
		
		deleteBtnAction : function(){
			var code = $('#code').val();
			return function(){
				var $this = $(this);
				var addressId = $this.attr('tip');
				var removeEl = function(){
					$this.closest('tr').remove();
				};
				base.yumConfirm(
		    			property.deleteAddressWarn,
		    			function(){
		    				$.ajax({
		    					url : requestContextPath + '/delAddressMail.action',
		    					type : 'post',
		    					data : {code : code, addressId : addressId},
		    					dataType : 'json',
		    					success : function(o){
		                        	if(o.code == serviceCode.SUC_CODE){
		                        		removeEl();
		                        		base.yumAlert(property.deleteSuccessfully);
		                        	}else{
		                        		base.yumAlert(property.deleteFailed);
		                        	}
		                        }
		    				});
		    			});
			};
		}
};

$(function(){
	address.init();
});